<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>定时器</title>
    <script type="text/javascript">
        window.onload = function () {
            let num = 1;
            let div = document.getElementById('div');
            let timer =setInterval(function (){
                div.innerHTML = num++;
                if (num === 11){
                    clearInterval(timer);
                }
            },1000);
        }
    </script>
</head>
<body>
<div id="div"></div>
</body>
</html>